package com.kxq.zhuoyue.controller;



import com.kxq.zhuoyue.po.AskAnswerGroup;
import com.kxq.zhuoyue.service.AskAnswerGroupService;
import com.kxq.zhuoyue.util.UUID;
import com.kxq.zhuoyue.util.result.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xjh
 * @since 2023-09-04
 */
@RestController
@RequestMapping("/askAnswerGroup")
public class AskAnswerGroupController {

    @Autowired
    private AskAnswerGroupService askAnswerGroupService;

    @PostMapping("/selectAll")
    public AjaxResult selectAll(){
        List<AskAnswerGroup> list = askAnswerGroupService.list();
        return AjaxResult.success("查询成功 ！",list);
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody AskAnswerGroup askAnswerGroup){
        String id = UUID.getOrderIdByTime();
        askAnswerGroup.setAskAnswerGroupId(id);
        boolean save = askAnswerGroupService.save(askAnswerGroup);
        if (save){
            return AjaxResult.success("保存成功 ！");
        }else {
            return AjaxResult.success("保存失败 ！");
        }
    }

    @PostMapping("/delete/{askAnswerGroupId}")
    public AjaxResult delete(@PathVariable String askAnswerGroupId){
        boolean b = askAnswerGroupService.removeById(askAnswerGroupId);
        if(b){
            return AjaxResult.success("删除成功 ！");
        }else {
            return AjaxResult.success("删除失败 ！");
        }
    }
}

